package cn.edu.hbwe.book.service;

import java.sql.SQLException;
import java.util.Date;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import cn.edu.hbwe.book.dao.UserDao;
import cn.edu.hbwe.book.entity.User;
import cn.edu.hbwe.book.exception.ActiveUserException;
import cn.edu.hbwe.book.exception.LoginException;
import cn.edu.hbwe.book.exception.RegistException;
import cn.edu.hbwe.book.utils.MaiUtils;
import javafx.fxml.LoadException;

public class UserService{

	public void userRegist(User user) throws RegistException, AddressException, MessagingException {
		// TODO Auto-generated method stub
		UserDao udao = new UserDao();
		try {
			udao.addUser(user);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RegistException("注册失败！");
		}
	}

	public User login(String username,String password) throws LoginException {
		UserDao dao = new UserDao();
		try {
			User user = dao.findByUnameAndPword(username,password);
			return user;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new LoginException("用户名或密码错误！");
		}
	}

	public void updateUserinfo(User user) throws RegistException {
		UserDao udao = new UserDao();
		try {
			udao.updateUserinfo(user);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RegistException("修改失败！");
		}
		
	}
}
